
package com.ami.kvm.jviewer.gui;

import com.ami.kvm.jviewer.Debug;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;

public class CaptureScreen extends Thread {
	private JFileChooser saveFileChooser;
	private File saveFile;
	private boolean run = true;
	private BufferedImage capturedFrame = null;

	public CaptureScreen(BufferedImage paramBufferedImage) {
		this.capturedFrame = paramBufferedImage;
	}

	public void run() {
		this.saveFileChooser = new JFileChooser();
		this.saveFile = new File("CapturedScreen.jpeg");
		this.saveFileChooser.setSelectedFile(this.saveFile);
		this.saveFileChooser.setFileFilter(new ImageFilter());
		this.saveFileChooser.setAcceptAllFileFilterUsed(false);
		while (this.run) {
			int i = this.saveFileChooser.showSaveDialog(JViewerApp.getInstance().getRCView());
			if (i == 0) {
				this.saveFile = this.saveFileChooser.getSelectedFile();

				if (!this.saveFile.getName().endsWith(".jpeg"))
					this.saveFile = new File(this.saveFile.getPath().concat(".jpeg"));
				saveImage();
			} else {
				this.run = false;
			}
		}
	}

	private void saveImage() {
		try {
			if (this.saveFile.exists()) {
				int i = JOptionPane.showConfirmDialog(
						this.saveFileChooser, LocaleStrings.getString("AF_1_CS") + " \"" + this.saveFile.getName()
								+ "\" " + LocaleStrings.getString("AF_2_CS"),
						LocaleStrings.getString("F_121_JVM"), 0, 3);

				if (i == 0) {
					ImageIO.write(this.capturedFrame, "jpeg", this.saveFile);
					this.run = false;
				} else {
					this.run = true;
				}
			} else {
				this.saveFile.createNewFile();
				ImageIO.write(this.capturedFrame, "jpeg", this.saveFile);
				this.run = false;
			}
		} catch (IOException localIOException) {
			Debug.out.println(localIOException);
		}
	}

	private class ImageFilter extends FileFilter {
		private ImageFilter() {
		}

		public boolean accept(File paramFile) {
			if (paramFile.isDirectory()) {
				return true;
			}

			String str = getExtension(paramFile);
			if (str != null) {
				if (str.equals("jpeg")) {
					return true;
				}
				return false;
			}

			return false;
		}

		private String getExtension(File paramFile) {
			String str1 = null;
			String str2 = paramFile.getName();
			int i = str2.lastIndexOf('.');

			if ((i > 0) && (i < str2.length() - 1)) {
				str1 = str2.substring(i + 1).toLowerCase();
			}
			return str1;
		}

		public String getDescription() {
			return "JPEG";
		}
	}
}

/*
 * Location:
 * D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\kvm\jviewer\gui\CaptureScreen
 * .class Java compiler version: 5 (49.0) JD-Core Version: 0.7.1
 */